<?php
/**
 * 手机端软终端凭证号验证
 */
if( !isset($_SESSION['memberID']) )
{
	echo '{"errormsg":"unlogin"}';
	exit;
}
include '../common/autoload.php';

include '../common/errBack.php';

$salerid=$_POST['salerid'];
$act = trim($_POST['act']);
$s = SoapInit::GetSoapInside();
#软终端验证
if($act=='check') {
	$certnum = trim(strip_tags($_POST['certnum']));
	if(empty($certnum))
	{
		echo '{"errormsg":"提示:凭证号不能为空"}';
		exit;
	}
	$res=$s->Terminal_Check_In($salerid, $certnum);
	if(is_numeric($res)){
		if($res==105){
			exit('{"errormsg":"提示:商户'.$salerid.'不存在此凭证号'.$certnum.'！"}');
		} elseif($res==121){
			exit('{"errormsg":"此凭证号已被验证，不能重复验证！"}');
		} elseif($res==119){
			exit('{"errormsg":"提示:订单状态出错，请联系技术人员！"}');
		} elseif($res==133){
            exit('{"errormsg":"提示:游玩时间未到，今日无法验证！"}');
        } elseif($res==134){
            exit('{"errormsg":"提示:游玩时间已超过，今日无法验证！"}');
        } else {
			exit('{"errormsg":"提示:'.$SoapRequestChk[$res].'"}');
		}
	}
	$result=simplexml_load_string($res);
	//订单号，流水号UUino
	$ordernum  =$result->Rec->UUordernum;
	$uuino     =(string)$result->Rec->UUino;
    $xml = $s->Order_Globle_Search('','','','','','','','','','','','',"$ordernum",'','','','');
	if(is_numeric($xml)){
		exit('{"error":"提示:'.judge($xml).'"}');
	}
	$out=array();
	$in=simplexml_load_string($xml);
    //print_r($in);
	$out['ordernum']     = (string)$ordernum;
	//$out['UUltitle']     = (string)$in->Rec->UUltitle;
	$out['UUttitle']     = (string)$in->Rec->UUttitle;

	$out['UUtnum']       = (string)$in->Rec->UUtnum;

	$out['UUordername']  = (string)$in->Rec->UUordername;
	$out['UUordertel']   = (string)$in->Rec->UUordertel;
	$out['successMsg']   = 'ok';
	$out['uuino']        = $uuino;//流水号
	echo json_encode($out);
}
#订单统计
elseif($act=='count') {
	$t = intval($_POST['t']);
	$tid = intval($_POST['ticketid']);
	//$ttitle = 
	$btime3 = date('Y-m-d').' 00:00:00';
	$etime3 = date('Y-m-d H:i:s');
	$status =1;
	$txt=trim($_POST['ttitle']);
	switch($t){
		case 1:
			$btime2 = date('Y-m-d');
			$status = 0;
			$btime3 ='';
			$etime3 ='';
			$txt.='当日未完成';
			break;
		case 2:
			$status = 1;
			$txt.='当日已完成';
			break;
		case 3:
			$btime3 = date('Y-m').'-01 00:00:00';
			$txt.='本月已完成';
			break;
		case 4:
			$t1 = $_POST['t1'];
			$t2 = $_POST['t2'];
			$y1=substr($t1,0,4);$m1=substr($t1, 4,2);$d1=substr($t1,6,2);
			$y2=substr($t2,0,4);$m2=substr($t2, 4,2);$d2=substr($t2,6,2);
			$d1 = $d1<10?'0'.$d1:$d1;
			$d2 = $d2<10?'0'.$d2:$d2;
			$btime3 = $y1.'-'.$m1.'-'.$d1.' 00:00:00';
			$etime3 = $y2.'-'.$m2.'-'.$d2.' 23:59:59';
			$txt.='从'.$y1.'-'.$m1.'-'.$d1.'至'.$y2.'-'.$m2.'-'.$d2.'已完成';
			break;
	}
	$count_sum  = $s->Order_Globle_Search("$salerid","","","$tid","","","","","$btime2","$btime2","$btime3","$etime3","","","","$status","","","1","",0,10,2);
	$t=explode(',',$count_sum);
	$total=$t[0];
	$tkNum=$t[1];
	$moneySum=$t[2];
	echo $txt.'订单<strong>'.$total.'</strong>单，门票数<strong>'.$tkNum.'</strong>张';
}elseif($act=='Code_Verify') {
    $outdate=$s->Terminal_Code_Verify(abs($_POST['orderid']+0),$_SESSION['memberID'],1);
    $outdate=simplexml_load_string($outdate);
    $code=$outdate->Rec[0]->UUcode;
    echo $code;
}